package com.ymtms.statisticalform.controller;

import com.ymtms.statisticalform.pojo.Emp;
import com.ymtms.statisticalform.pojo.EmpBusiness;
import com.ymtms.statisticalform.service.EmpBusinessService;
import com.ymtms.statisticalform.vo.GridRequest;
import com.ymtms.statisticalform.vo.GridResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@CrossOrigin
@RequestMapping("/empbusiness")
public class EmpBusinessController {

    @Autowired
    EmpBusinessService empBusinessService;

    @RequestMapping("/work")
    @ResponseBody
    public Map work(String customerCode,String year,String month){
        System.out.println("work"+new Date());
        Map map = new HashMap();
        List<Emp> emps=empBusinessService.findEmp();
        System.out.println(emps);
        System.out.println(new Date());
        List<EmpBusiness> empBusinesses=empBusinessService.findEmpBusiness(emps, year, month);
        System.out.println(empBusinesses);
        System.out.println(new Date());
        map.put("msg",emps);
        return map;
    }

    /**
     * 员工业务统计
     * @param gridRequest
     * @param customerCode
     * @param year
     * @param month
     * @return
     */
    @RequestMapping("/workLay")
    @ResponseBody
    public GridResult<EmpBusiness> workLay(GridRequest gridRequest, /* 封装页面中laiyu表格所传过来的基本信息*/
                                           String customerCode,String year,String month){

        System.out.println("gridRequest:"+gridRequest);
        System.out.println("customerCode:"+customerCode);
        System.out.println("year:"+year);
        System.out.println("month:"+month);

        List<Emp> emps =empBusinessService.findEmp();
        int size = emps.size();
        System.out.println("开始:"+new Date());
        GridResult<EmpBusiness> result = empBusinessService.queryByPage(
                gridRequest,size, year, month);
        System.out.println("结束:"+new Date());

//        GridResult<CollectingMoneyBalance> result = collectingMoneyBalanceService.queryByPage(Integer.parseInt(params.get("page")), Integer.parseInt(params.get("limit")));
//        GridResult<CollectingMoneyBalance> result = collectingMoneyBalanceService.queryByPage(1,10);
        result.setCode(0);
        result.setMsg("");
        System.out.println(result);
        return result;
    }
}
